package job;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;

import models.DeviceHealth;
import models.SystemParams;
import notifiers.MailUtils;
import play.jobs.Every;
import play.jobs.Job;
import play.jobs.On;
import services.DeviceHealthService;
import services.DeviceService;
import services.HraDetailService;
import services.SystemParamService;
import utils.BizConstants;
import vos.DeviceVo;

/**
 * 设备状态的检查规则
 * 
 * @ClassName: CheckDeviceStatus 
 * @author: wangsm
 * @date: 2016年6月4日 下午5:05:41
 */
@On("0 0 23 * * ? ")
public class CheckDeviceStatus extends Job {
	/**
	 * 检查设备状态
	 * 规则为每日的23点检查今日是否有数据上传，有则为健康，没有则为不健康
	 */
	@Override
	public void doJob()throws Exception{
		String emailparam=SystemParamService.getByCacheId(BizConstants.DEVICE_STATUS_EMAIL);
		if(emailparam==null||StringUtils.isEmpty(emailparam)){
			return;
		}
		DateTime date =DateTime.now();
		List<String> hraids=HraDetailService.listNewHraids(date);
		DeviceService.updateDeviceStatus(hraids,emailparam);
	}
}
